package com.alan.weather.controller;

import com.alan.weather.common.responseResult.R;
import com.alan.weather.entity.weather.*;
import com.alan.weather.utils.DateUtil;
import com.alan.weather.utils.SystemUtils;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/weather")
public class WeatherController {

    /*
        查询所有数据
     */
    @GetMapping("/getAll")
    public R getAll() {
        return R.success("200");
    }

    /*
        查询某日情况
     */
    @GetMapping("/getOneDay")
    public R getDay(String date) {
        String transformed = DateUtil.transform(date);//转换日期格式
        WeatherData_OneDay data_oneDay = SystemUtils.query_one_day(transformed);
        return R.success(data_oneDay);
    }


    /*
        查询最高温
     */
    @GetMapping("/getHighest")
    public R getHighest() {
        WeatherData_HighestEveryYear highest = SystemUtils.query_highest();
        return R.success(highest.getYears());
    }

    /*
        查询最低温
     */
    @GetMapping("/getLowest")
    public R getLowest() {

        WeatherData_LowestEveryYear lowest = SystemUtils.query_lowest();
        return R.success(lowest.years);
    }

    /*
        查询最低温
    */
    @GetMapping("/getAvg")
    public R getAvg() {

        WeatherData_AverageEveryYear average = SystemUtils.query_average();
        return R.success(average.years);
    }

    /*
        查询降雨量
     */
    @GetMapping("/getRainy")
    public R getRainy() {

        WeatherData_RainyEveryYear rainy = SystemUtils.query_rainy();
        return R.success(rainy.year);
    }

    /*
        天气预测（一天）
     */
    @GetMapping("/predictOneDay")
    public R predictOne(String date) {

        WeatherData_PredictOneDay predictOneDay = SystemUtils.predictOneDay(DateUtil.transform(date));
        return R.success(predictOneDay);
    }

    /*
        天气预测（七天）
    */
    @GetMapping("/predictSevenDay")
    public R predictSeven(String date) {

        WeatherData_PredictOneWeek oneWeek = SystemUtils.predictOneWeek(DateUtil.transform(date));
        return R.success(oneWeek.week);
    }

    /*
        某年每个月最高温度
     */
    @GetMapping("/getMonth")
    public R getMonth(String date) {

        WeatherData_MouthOfYear mouthOfYear = SystemUtils.mouthOfYear(date);
        return R.success(mouthOfYear.mouths);
    }




}
